package cn.hy.today;

class Solution_2397 {
    public int maximumRows(int[][] matrix, int numSelect) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[] mask = new int[m]; // 二进制数组
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                // 列最多不会超过12
                mask[i] += matrix[i][j] << n - j - 1;
            }
        }
        int ans = 0;
        int cur = 0;
        int limit = 1 << n;
        // 枚举所有的数
        while (++cur < limit) {
            // 判断是否有这么多1
            if (Integer.bitCount(cur) != numSelect) {
                continue;
            }
            int t = 0;
            for (int i = 0; i < m; i++) {
                // 相等说明找到一个数
                if ((mask[i] & cur) == mask[i]) {
                   t++;
                }
            }
            ans = Math.max(ans, t);
        }
        return ans;

    }
}